package com.wjqy.controller;

import com.wjqy.entity.*;
import com.wjqy.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("admin2")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "scenic",method = RequestMethod.POST)
    public CommonReturnEntity insertScenic(Scenic scenic){
        int i = adminService.insertScenic(scenic);
        if (i>0){
            return CommonReturnEntity.success("添加数据成功");
        }
        return CommonReturnEntity.fail("添加数据失败");
    }

    @RequestMapping(value = "/scenic",method = RequestMethod.PUT)
    public CommonReturnEntity updateScenic(Scenic scenic){
        int i = adminService.updateScenic(scenic);
        if (i>0){
            return CommonReturnEntity.success("更新成功");
        }
        return CommonReturnEntity.fail("更新失败");
    }

    @RequestMapping(value = "scenic",method = RequestMethod.DELETE)
    public CommonReturnEntity deleteScenic(Integer id){
        int i = adminService.deleteScenic(id);
        if (i>0){
            return CommonReturnEntity.success("删除成功");
        }
        return CommonReturnEntity.fail("删除失败");
    }

    /*活动管理*/

    @RequestMapping(value = "active",method = RequestMethod.GET)
    public CommonReturnEntity findAllActive(Integer id){
        List<Active> allActivies = adminService.findAllActivies(id);
        return CommonReturnEntity.success(allActivies);
    }


    @RequestMapping(value = "active",method = RequestMethod.POST)
    public CommonReturnEntity insertActive(Active active){
        int i = adminService.insertActive(active);
        if (i>0){
            return CommonReturnEntity.success("添加数据成功");
        }
        return CommonReturnEntity.fail("添加数据失败");
    }

    @RequestMapping(value = "active",method = RequestMethod.PUT)
    public CommonReturnEntity updateActive(Active active){
        int i = adminService.updateActive(active);
        if (i>0){
            return CommonReturnEntity.success("更新成功");
        }
        return CommonReturnEntity.fail("更新失败");
    }

    @RequestMapping(value = "active",method = RequestMethod.DELETE)
    public CommonReturnEntity deleteActive(Integer id){
        int i = adminService.deleteActive(id);
        if (i>0){
            return CommonReturnEntity.success("删除成功");
        }
        return CommonReturnEntity.fail("删除失败");
    }
    /*打卡推荐管理*/
    @RequestMapping(value = "rcmd",method = RequestMethod.GET)
    public CommonReturnEntity findAllRecommend(Integer id){
        List<Recommend> allRcmd = adminService.findAllRcmd(id);
        return CommonReturnEntity.success(allRcmd);
    }


    @RequestMapping(value = "rcmd",method = RequestMethod.POST)
    public CommonReturnEntity insertRecommend(Recommend rcmd){
        int i = adminService.insertRecommend(rcmd);
        if (i>0){
            return CommonReturnEntity.success("添加数据成功");
        }
        return CommonReturnEntity.fail("添加数据失败");
    }

    @RequestMapping(value = "rcmd",method = RequestMethod.PUT)
    public CommonReturnEntity updateRecommend(Recommend rcmd){
        int i = adminService.updateRecommend(rcmd);
        if (i>0){
            return CommonReturnEntity.success("更新成功");
        }
        return CommonReturnEntity.fail("更新失败");
    }

    @RequestMapping(value = "rcmd",method = RequestMethod.DELETE)
    public CommonReturnEntity deleteRecommend(Integer id){
        int i = adminService.deleteRecommend(id);
        if (i>0){
            return CommonReturnEntity.success("删除成功");
        }
        return CommonReturnEntity.fail("删除失败");
    }

    @RequestMapping(value = "hello",method = RequestMethod.GET)
    public CommonReturnEntity deleteRecommend(){
        return CommonReturnEntity.success("hello world");
    }

    @RequestMapping(value = "createcdk",method = RequestMethod.POST)
    public CommonReturnEntity createCDK(int num,int scenicId){
        int cdkey = adminService.createCdkey(num, scenicId);
        if (cdkey<1){
            return CommonReturnEntity.fail("生成cdk失败！");
        }
        return CommonReturnEntity.success("生成cdk成功！");
    }

    @RequestMapping("listverifyuser")
    public CommonReturnEntity listVerifyUser(){
        List<User> users = adminService.listVerifyUser();
        return CommonReturnEntity.success(users);
    }

    /*@MethodName: chageUserStatus
     * @Author: man
     * @Description: 审核用户
     * @Date:  18:13 2020/7/6
     * @Param: user.id ,user.status
     * @Return: com.wjqy.entity.CommonReturnEntity
    **/
    @RequestMapping("chageuserstatus")
    public CommonReturnEntity chageUserStatus(User user){
        boolean b = adminService.changeUserStatus(user);
        return b?CommonReturnEntity.success("审核完成"):CommonReturnEntity.fail("审核失败");
    }

    /*@MethodName: setTopLevel
     * @Author: man
     * @Description: 设置1级账号
     * @Date:  18:27 2020/7/6
     * @Param: id , scenicId
     * @Return: com.wjqy.entity.CommonReturnEntity
    **/
    @RequestMapping("settoplevel")
    public CommonReturnEntity setTopLevel(User user){
        if (user.getId()==null){
            return CommonReturnEntity.fail("请传入用户id");
        }
        boolean b = adminService.setTopLevel(user);
        return b?CommonReturnEntity.success("设置顶级用户成功"):CommonReturnEntity.fail("设置失败");
    }
}
